initDatePlugin();

function speech() {
    var speechTechnique = $("#speechTechnique").val();
    $('#content').val(speechTechnique);
    $("#speechTechnique").val("");
}

/**
 * 绑定时间控件
 */
function initDatePlugin() {
    var dcTime = laydate.render({
        elem: '#dcTime'
    });
}

/**
 * textarea回车按钮监听事件
 * @param event
 */
document.onkeydown = function (event) {
    var event = event || window.event;
    if (event.ctrlKey && event.keyCode == 13)  {
        var dcTime = $("#dcTime").val();
        var coordinationName = $("#coordinationName").val();
        var content = $("#content").val();
        var trackstate = $("#trackstate").val();
        var companyId = $("#companyId").val();

        if (content == ""){
            swal({
                title: "填写有误",
                text: "跟单记录不能为空"
            });
            return false;
        }


        $.ajax({
            url : "/trackRecord/trackingLog_save",
            type : "POST",
            traditional : true,
            dataType : "JSON",
            data : {
                dcTime : dcTime,
                companyId : companyId,
                coordinationName : coordinationName,
                content : content,
                trackState : trackstate
            },
            success : function(data) {
                var d = new Date(data.addTime);
                if (data.coordinationName != ""){
                    $("#chatDiv").append('<div class="chat-message"><img class="message-avatar" src="'+data.coordinationImg+'" alt="'+data.coordinationName+'" ><div class="message">' +
                        '<a class="message-author">'+data.userName+'</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' +
                        '<span style="color:#cfb53b;" class="fa fa-phone"></span><a class="message-author" style="color:#cfb53b;" >'+data.coordinationName+'</a>' +
                        '<span class="message-date" >'+d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate() + ' ' + d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds()+'</span>' +
                        '<span class="message-content" >'+data.content+'</span></div></div>');
                }else{
                    $("#chatDiv").append('<div class="chat-message"><img class="message-avatar" src="'+data.userImg+'" alt="'+data.userName+'" ><div class="message">\n' +
                        '<a class="message-author">'+data.userName+'</a>' +
                        '<span class="message-date" >'+d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate() + ' ' + d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds()+'</span>' +
                        '<span class="message-content" >'+data.content+'</span></div></div>');
                }

                var chat = document.getElementById("chatDiv");
                chat.scrollTop = chat.scrollHeight;

                $("#coordinationName").val("");
                $("#dcTime").val("");
                $("#content").val("");
            }
        });
    }

};